package com.cnsunrun.framworksimple.mode

import kotlin.properties.Delegates

/**
 * Created by WQ on 2017/6/27.
 */

class ObservableMode<T> {

    constructor(init:ObservableMode<T>.()->Unit){
        init()
    }
    var listener: OnModeChangeListener<T>? = null
    var mode: T? by Delegates.observable(null as T?, {
        preVal, oldVal, newVal ->
             listener?.onTextChanged(newVal)
    })

    fun listener(listener:(T?)->Unit){
        this.listener=object :OnModeChangeListener<T>{
            override fun onTextChanged(newMode: T?) {
                listener(newMode)
            }
        }
    }

//    listener?.onTextChanged(newVal)
    interface OnModeChangeListener<T> {
        fun onTextChanged(newMode: T?):Unit
    }
}
